from proto.user import user_pb2, user_pb2_grpc
import grpc
from concurrent import futures


class Greeter(user_pb2_grpc.GreeterServicer):

    def SayHello(self, request, context):
        """定义PAC对于的具体的服务包含方法"""

        return user_pb2.HelloReply(message=f"你好, {request.name}")

    def SayHelloAgain(self, request, context):
        return user_pb2.HelloReply(message=f"不好, {request.name}")


if __name__ == '__main__':
    # instance server
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    # register server
    user_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
    # start
    server.add_insecure_port('0.0.0.0:5001')
    print("start service user...")
    server.start()
    server.wait_for_termination()
